package com.example.controller;

import com.example.mapper.GoodsMapper;
import com.example.model.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private GoodsMapper goodsMapper;
    /**
     * 获取所有的商品信息
     * @return
     */
    @RequestMapping("list")
    public List<Goods> list(){
        List<Goods> goods = goodsMapper.selectList(null);
        return goods;
    }
    /**
     * 实现添加商品
     */
    @RequestMapping("/add")
    public String add(Goods goods){
       goodsMapper.insert(goods);
       return "success";
    }
    /**
     * 根据商品的编号更新商品信息
     */
    @RequestMapping("/update")
    public String update(Goods goods){
        goodsMapper.updateById(goods);
        return "success";
    }
    /**
     * 根据商品的编号删除对应的商品信息
     */
    @RequestMapping("/delete")
    public String delete(Integer id){
        goodsMapper.deleteById(id);
        return "success";
    }

}
